package logic

import (
	"context"
	"errors"
	"srv/model/mysql"

	"srv/internal/svc"
	"srv/renrenzu"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodAddLogic {
	return &GoodAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodAddLogic) GoodAdd(in *renrenzu.GoodAddRequest) (*renrenzu.GoodAddResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Goods{
		GoodsTitle:      in.GoodsTitle,
		GoodsCover:      in.GoodsCover,
		GoodsPrice:      float64(in.GoodsPrice),
		GoodsStock:      int(in.GoodsStock),
		GoodsCollection: int(in.GoodsCollection),
		GoodsState:      int(in.GoodsState),
	}
	err := g.Create()
	if err != nil {
		logx.Error("添加商品失败", err)
		return nil, errors.New("添加商品失败")
	}
	return &renrenzu.GoodAddResponse{GoodsId: int64(g.ID)}, nil
}
